package eddy.yang.wordpad;
import java.io.File;
import java.util.ArrayList;
import javax.swing.filechooser.FileFilter;

public class ExtensionFileFilter extends FileFilter{
   public void addExtension(String extension) {
      if(!extension.startsWith(".")) {
         extension = "." + extension;
      }
      extensions.add(extension);
   }
   
   public void setDescription(String description) {
      this.description = description;
   }

   public boolean accept(File f) {
      if(f.isDirectory()) return true;
      String name = f.getName().toLowerCase();
      
      for(String estension: extensions) {
         if(name.endsWith(estension))
            return true;
      }
      return false;
   }
   
   public String getDescription() {
      return this.description;
   }
   
   private String description;
   private ArrayList<String> extensions = new ArrayList<String>(); 
}
